﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using System.Collections.Generic;
using System.Threading.Tasks;
using Zocono.Infrastructure.Common;
using Zocono.WCS.Admin.Common;
using Zocono.WCS.Admin.Models.Module;
using Zocono.WCS.Admin.Models.User;
using Zocono.WCS.Application.AppTraces;
using Zocono.WCS.Application.AppUserManage;
using Zocono.WCS.WMSApiDomain.WebApi;

namespace Zocono.WCS.Admin.Controllers.MonitorManageMoudle
{
    public class MonitorViewController : BaseController
    {
        private readonly UserApp _userApp;
        private readonly IHttpContextAccessor _accessor;
        public MonitorViewController(UserApp userApp, TracesApp tracesApp, IMemoryCache memoryCache, IHttpContextAccessor httpContextAccessor) : base(memoryCache, tracesApp, httpContextAccessor)
        {
            _userApp = userApp;
            _accessor = httpContextAccessor;
        }
    
        /// <summary>
        /// 获取当前登录用户信息
        /// </summary>
        /// <returns></returns>
        public UserModel GetUserModel()
        {
            var token = GetCookiesValue("User_Token");
            if (!string.IsNullOrEmpty(token))
            {
                return JsonUtils.Deserialize<UserModel>(DesHelper.DecryptDES(token));
            }
            return null;
        }
        /// <summary>
        /// 获取cookie的value
        /// </summary>
        /// <param name="key">键</param>
        /// <returns>返回对应的值</returns>
        protected string GetCookiesValue(string key)
        {
            _accessor.HttpContext.Request.Cookies.TryGetValue(key, out string value);
            if (string.IsNullOrEmpty(value))
                value = string.Empty;
            return value;


        }

        [BasicAuth]
        public async Task<IActionResult> Floor1Async()
        {
            var signalRUrl = JsonConfigurationHelper.GetJson("appsettings.json", "signalRUrl");
            ViewBag.signalRUrl = signalRUrl;
            var user = GetUserModel();
           

            return View(user);
        }
        [BasicAuth]
        public async Task<IActionResult> Floor2Async()
        {
            var signalRUrl = JsonConfigurationHelper.GetJson("appsettings.json", "signalRUrl");
            ViewBag.signalRUrl = signalRUrl;
            var user = GetUserModel();

            return View(user);
        }
        [BasicAuth]
        public async Task<IActionResult> Floor3Async()
        {
            var signalRUrl = JsonConfigurationHelper.GetJson("appsettings.json", "signalRUrl");
            ViewBag.signalRUrl = signalRUrl;
            var user = GetUserModel();
           

            return View(user);
        }
        [BasicAuth]
        public async Task<IActionResult> Floor4Async()
        {
            var signalRUrl = JsonConfigurationHelper.GetJson("appsettings.json", "signalRUrl");
            ViewBag.signalRUrl = signalRUrl;
            var user = GetUserModel();
           

            return View(user);
        }
        [BasicAuth]
        public async Task<IActionResult> Floor5Async()
        {
            var signalRUrl = JsonConfigurationHelper.GetJson("appsettings.json", "signalRUrl");
            ViewBag.signalRUrl = signalRUrl;
            var user = GetUserModel();
           
            return View(user);
        }

        public async Task<JsonResult> GetHynnStateDataAsync()
        {
            var res = await WCSMessageWithWMSApi.GetHynnStateAsync();
            return Json(res);
        }
    }
}
